package com.ruoyi.logistic.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.logistic.domain.NetworkUndertakeCentreTransferCollect;
import com.ruoyi.logistic.domain.NetworkUndertakeCentreTransferDetail;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.vo.NetworkUndertakeCentreDetailVo;
import com.ruoyi.logistic.domain.vo.NetworkUndertakeCentreTransferCollectVo;
import com.ruoyi.logistic.domain.vo.NetworkUndertakeCentreTransferDetailVo;
import com.ruoyi.logistic.enums.NetworkUndertakeCentreTransferCollectEnum;
import com.ruoyi.logistic.enums.NetworkUndertakeCentreTransferDetailEnum;
import com.ruoyi.logistic.mapper.NetworkUndertakeCentreTransferCollectMapper;
import com.ruoyi.logistic.mapper.NetworkUndertakeCentreTransferDetailMapper;
import com.ruoyi.logistic.service.NetworkUndertakeCentreTransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class NetworkUndertakeCentreTransferServiceImpl implements NetworkUndertakeCentreTransferService {
    @Autowired
    private NetworkUndertakeCentreTransferDetailMapper networkUndertakeCentreTransferDetailMapper;
    @Autowired
    private NetworkUndertakeCentreTransferCollectMapper networkUndertakeCentreTransferCollectMapper;
    @Override
    public List<NetworkUndertakeCentreTransferDetail> selectAll(PageDate pageDate) {
        PageHelper.startPage(pageDate);
        return networkUndertakeCentreTransferDetailMapper.selectAll();
    }

    @Override
    public Boolean insert(NetworkUndertakeCentreTransferDetail networkUndertakeCentreTransferDetail) {
        return networkUndertakeCentreTransferDetailMapper.insert(networkUndertakeCentreTransferDetail);
    }

    @Override
    public Boolean update(NetworkUndertakeCentreTransferDetail networkUndertakeCentreTransferDetail) {
        return networkUndertakeCentreTransferDetailMapper.update(networkUndertakeCentreTransferDetail);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return networkUndertakeCentreTransferDetailMapper.deleteById(id);
    }

    @Override
    public List<NetworkUndertakeCentreTransferDetail> search(NetworkUndertakeCentreTransferDetailVo networkUndertakeCentreTransferDetailVo) {
        PageHelper.startPage(networkUndertakeCentreTransferDetailVo.getPageDate());
        return networkUndertakeCentreTransferDetailMapper.search(networkUndertakeCentreTransferDetailVo);
    }

    @Override
    public List<NetworkUndertakeCentreTransferCollect> transferCollect(NetworkUndertakeCentreTransferCollectVo networkUndertakeCentreTransferCollectVo) {
        PageHelper.startPage(networkUndertakeCentreTransferCollectVo.getPageDate());
        List<NetworkUndertakeCentreTransferCollect> transferCollectList = networkUndertakeCentreTransferCollectMapper.transferCollect(networkUndertakeCentreTransferCollectVo);
        assert transferCollectList != null;
        for (NetworkUndertakeCentreTransferCollect transferCollect : transferCollectList){
            if (networkUndertakeCentreTransferCollectVo.getCollectDimensionality() == 1){
                transferCollect.setSettleDate(networkUndertakeCentreTransferCollectVo.getStartTime() + "至" + networkUndertakeCentreTransferCollectVo.getEndTime());
            }else {
                transferCollect.setSettleDate(networkUndertakeCentreTransferCollectVo.getMonth());
            }
        }
        return transferCollectList;
    }

    @Override
    public List<TableVo> initTable() {
        List<TableVo> list = new ArrayList<>();
        TableVo tableVo = new TableVo();
        String[] fields = {"transportCode", "settleDate", "amountPayable", "transferFee", "extraFee", "addFee"
                , "preAmountReceived", "settleWeight", "pullAvgWeight","volumeWeight","lengthWidthHeight","weight"
                , "orderClientId", "printClerk", "aimProvince","aimCity","transportType","itemType"
                , "sheetSource", "receivingClerk", "signNetworkId","signTime","remark"
        };
        for (String field : fields) {
            tableVo = new TableVo();
            tableVo.setFields(field);
            list.add(tableVo);
        }
        for (TableVo vo : list) {
            vo.setTranslate(NetworkUndertakeCentreTransferDetailEnum.getValue(vo.getFields()));
        }
        return list;
    }

    @Override
    public List<TableVo> initTableCollect() {
        List<TableVo> list = new ArrayList<>();
        TableVo tableVo = new TableVo();
        String[] fields = {"settleDate", "displayName", "totalTicket", "totalSettleWeight", "amountPayable", "transferFee"
                , "extraFee", "addFee", "preAmountReceived"
        };
        for (String field : fields) {
            tableVo = new TableVo();
            tableVo.setFields(field);
            list.add(tableVo);
        }
        for (TableVo vo : list) {
            vo.setTranslate(NetworkUndertakeCentreTransferCollectEnum.getValue(vo.getFields()));
        }
        return list;
    }
}
